﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.ServiceLocation;
using AzureGames.Model;
using AzureGames.Data.Implementation.ServiceEntities;

namespace AzureGames.Data.Implementation
{
    public class PlayerRepository : IPlayerRepository
    {
        public AIPlayerRepository AIPlayerRepository { get; set; }
        public UserRepository UserRepository { get; set; }

        public PlayerRepository() 
        {
            AIPlayerRepository = new AIPlayerRepository();
            UserRepository = new UserRepository();
        }        

        public Model.Player GetPlayer(string playerID)
        {
            // TODO: not sure if we should re-model AIPlayer/User/AnonymousPlayer/Player
            //       as Azure does not support a base class concept well
            //       for now, I made the ID a string value and for Users this is a GUID
            //       but for AIPlayers this is the gamedefinition, a colon, followed by a GUID
            if (playerID.Contains(':'))
                return AIPlayerRepository.GetAIPlayer(playerID);
            else
            {
                if(playerID==Guid.Empty.ToString())                    
                    return new Model.AnonymousPlayer();

                return UserRepository.GetUser(playerID);
            }
        }       
    }
}
